<?php 
declare (strict_types = 1);
namespace app\api\controller;
use app\common\controller\Api;
use think\Request;
class BusinessStatus extends Api
{
    //查询日期
    public function index()
    {
        $this->businessCheckLogin();
        $post = param();
        if(!isset($post['date'])) return msgerror('参数缺失');
        //下午场
        $arr['wx'] = $this->model->where([
            ['business_id','=',$this->businessinfo['id']],
            ['date','=',$post['date']],
            ['type','=',1]
        ])->find();
        //晚上场
        $arr['ws'] = $this->model->where([
            ['business_id','=',$this->businessinfo['id']],
            ['date','=',$post['date']],
            ['type','=',2]
        ])->find();
        //修仙场
        $arr['xx'] = $this->model->where([
            ['business_id','=',$this->businessinfo['id']],
            ['date','=',$post['date']],
            ['type','=',3]
        ])->find();
        return datasuccess($arr);
    }
    //锁场
    public function sc()
    {
        $this->businessCheckLogin();
        $post = param();
        if(!isset($post['date']) || !isset($post['type'])) return msgerror('参数缺失');
        $data = $this->model->where([['date','=',$post['date']],['type','=',$post['type']]])->find();
        if(!empty($data) && !empty($data->toArray()))
        {
            //存在锁场记录，就是解锁操作
            $this->model::destroy($data->id);
        }else{
            //不存在锁场记录，就是就行锁场操作
            $this->model->save(['business_id'=>$this->businessinfo['id'],'date'=>$post['date'],'type'=>$post['type']]);
        }
        return datasuccess([],'操作成功');
    }
}